<template>
  <el-tabs type="border-card">
    <el-tab-pane label="我关心的工作">
      <div class="page-controller">
        <!-- 查询条件区 -->
        <FISearchForm
          class="box-radius2"
          ref="ruleFormRef"
          :id="`inqu_${tableId}`"
          v-model:form-value="state.query"
          :table-column="columns"
          :defaultFormNum="15"
          :excludeValues="['taskArriveTime', 'beginTime']"
          :wrapperSpan="wrapperSpan"
          @submit="searchFn"
          @reset="() => (state.query.beginTime = null)"
        >
          <el-col :span="wrapperSpan" class="flex-center">
            <!-- <FIFormItem name="taskArriveTime" label="任务到达时间">
              <FIDatePicker
                v-model="state.query.taskArriveTime"
                value-format="YYYYMMDD"
                type="daterange"
                start-placeholder=""
                end-placeholder=""
              />
            </FIFormItem> -->
            <FIFormItem class="date-range-class" name="taskArriveTime" label="任务到达时间">
              <FIDatePicker
                value-format="YYYYMMDD"
                v-model="state.query.beginTime"
                placeholder="请选择"
                :disabled-date="disabledBeginDate"
              />
              <FIDatePicker
                value-format="YYYYMMDD"
                v-model="state.query.endTime"
                placeholder="请选择"
                :disabled-date="disabledEndDate"
              />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="processDefKey" label="流程名称">
              <ProcessName v-model="state.query.processDefKey" />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="taskDefKey" label="任务名称">
              <TaskName v-model="state.query.taskDefKey" />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="starter" label="流程发起人">
              <FISelect
                v-model="state.query.starter"
                valueCustom="loginName"
                :props="{ value: 'loginName', label: 'userCName' }"
                :options="allStarterArr"
                :displayKey="['loginName', 'userCName']"
                clearable
                filterable
              />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="startDeptId" label="发起部门">
              <DeptTree v-model="state.query.startDeptId" />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="productName" label="产品名称">
              <FIInput v-model="state.query.productName" clearable />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="prodPeriodNo" label="产品分期号">
              <FIInput v-model="state.query.prodPeriodNo" clearable />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="consignee" label="委托人">
              <FISelect
                v-model="state.query.consignee"
                valueCustom="loginName"
                :props="{ value: 'loginName', label: 'userCName' }"
                :options="allStarterArr"
                :display-key="['loginName', 'userCName']"
                filterable
              />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="sequenceId" label="流程实例号">
              <FIInput v-model="state.query.sequenceId" clearable />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="instSubject" label="业务说明">
              <FIInput v-model="state.query.instSubject" clearable />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="ifDeputedTask" label="显示代理出去任务">
              <FISelect
                v-model="state.query.ifDeputedTask"
                valueCustom="value"
                :options="[
                  { value: '0', label: '不显示' },
                  { value: '1', label: '显示' },
                ]"
                clearable
              />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="claimCond" label="任务领取状态">
              <FISelect
                v-model="state.query.claimCond"
                valueCustom="value"
                :options="[
                  { value: '0', label: '全部' },
                  { value: '1', label: '未领取与已领取' },
                  { value: '2', label: '已被领取' },
                ]"
                clearable
              />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="taskStatus" label="任务状态">
              <FISelect
                v-model="state.query.taskStatus"
                valueCustom="value"
                :options="[
                  { value: 'open', label: '正运行' },
                  { value: 'open_return', label: '回退运行' },
                ]"
                clearable
              />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="remark" label="备注">
              <FIInput v-model="state.query.remark" clearable />
            </FIFormItem>
          </el-col>
          <el-col :span="wrapperSpan" class="flex-center">
            <FIFormItem name="approveDeadline" label="完成截止时间">
              <FIDatePicker value-format="YYYYMMDD" v-model="state.query.approveDeadline" type="date" />
            </FIFormItem>
          </el-col>
        </FISearchForm>
        <!-- 查询结果列表区 -->
        <FITable
          ref="tableRef"
          class="box-radius2 margin-top20"
          title="记录集"
          :id="`result_${tableId}`"
          :data="state.dataList"
          primaryKey="id"
          v-model:columns="columns"
          :isLoading="isTableLoading"
          :saveSuccessful="saveSuccessful"
          :pageConfig="pageConfig"
          :show-save-model="false"
          @table-refresh="searchFn"
          @selection-change="handleSelectionChange"
          @size-change="handleSizeChange"
          @current-page-change="handleCurrentChange"
          @action-click="handleActionClick"
        >
          <!-- 自定义列 moduleEname1 -->
          <!-- <template #manage="{ scope }">
            <FIButton border size="small">查看</FIButton>
            <FIButton border size="small">图形监控</FIButton>
          </template> -->
          <template #headerBtn>
            <FIPopconfirmBtn
              title="您是否确认批量领取选中数据吗？"
              beforePopText="请选择一条数据"
              buttonText="批量领取"
              :btn-binds="{ border: true }"
              :isVisible="!!checkedRows.length"
              @confirm="bulkOperation('claim')"
            />
            <FIPopconfirmBtn
              class="margin-left12"
              title="您是否确认批量打开选中数据吗？"
              beforePopText="请选择一条数据"
              buttonText="批量打开"
              :btn-binds="{ border: true }"
              :isVisible="!!checkedRows.length"
              @confirm="bulkOperation('open')"
            />
            <FIPopconfirmBtn
              class="margin-left12"
              title="您是否确认批量委托选中数据吗？"
              beforePopText="请选择一条数据"
              buttonText="批量委托"
              :btn-binds="{ border: true }"
              :isVisible="!!checkedRows.length"
              @confirm="bulkOperation('delegate')"
            />
            <FIButton class="margin-left12" id="export" :loading="exportLoading" type="primary" @click="exportClick"
              >导出</FIButton
            >
          </template>
        </FITable>
      </div>
    </el-tab-pane>
    <el-tab-pane label="设置我关心的流程">
      <setting v-if="allProcessesArr && allProcessesArr.length" :optins="allProcessesArr"></setting>
    </el-tab-pane>
  </el-tabs>
  <FIModel
    v-model="reassignModelShow"
    title="选择委托人"
    width="620px"
    :confirmLoading="reassignForm.confirmLoading"
    @confirm="reassignConfirm"
  >
    <FIForm :model="reassignForm">
      <FIFormItem name="loginName" label="委托人">
        <!-- <FISelect
          v-model="reassignForm.loginName"
          valueCustom="loginName"
          :props="{ value: 'loginName', label: 'userCName' }"
          :options="allStarterArr"
          clearable
        >
          <template #option="{ scope }">
            <span>{{ scope.loginName }}--{{ scope.userCName }}</span>
          </template>
        </FISelect> -->
        <FIAutoInput
          v-model="reassignForm.userCName"
          :options="allStarterArr"
          value-key="userCName"
          :displayKey="['loginName', 'userCName']"
          placeholder="请输入"
          clearable
          @select="
            (item) => {
              reassignForm.loginName = item.loginName
            }
          "
        />
      </FIFormItem>
    </FIForm>
  </FIModel>
  <HisDialog
    :visible="hisDialogVisible"
    :task-id="hisTaskId"
    @update:visible="(newValue) => (hisDialogVisible = newValue)"
  ></HisDialog>
  <div id="linksContainer"></div>
</template>
<script lang="ts" setup>
import { reactive, onMounted, ref, watch } from 'vue'
import FISearchForm from '@/components/FISearchForm.vue'
import FIFormItem from '@/components/FIFormItem.vue'
import setting from './setting.vue'
import FIInput from '@/components/FIInput.vue'
import FIPopconfirmBtn from '@/components/FIPopconfirmBtn.vue'
import FITable from '@/components/FITable/index.vue'
import FISelect from '@/components/FISelect/index.vue'
import FIDatePicker from '@/components/FIDatePicker.vue'
import DeptTree from '../../components/DeptTree.vue'
import ProcessName from '../../components/ProcessName.vue'
import TaskName from '../../components/TaskName.vue'
import HisDialog from '../../components/HisDialog.vue'

import {
  apiQueryAllProcesses,
  apiQueryUser,
  apiMyFavorTaskExport,
  apiClaimTasksBulk,
  apiReassignTasksBulk,
} from '@/api/modules/EWPT.js'
import { apiRequestPost } from '@/api/globalApi.js'
import { useMessage } from '@/hooks/message' // 通用message消息提示框
import type { PageConfig, Column } from '@/types/components'
import { useRoute, useRouter } from 'vue-router'
import { initSearchData, openUrlFn, useRouteNavigation } from '@/utils/common'
import { getQueryTableCache } from '@/utils/cacheUtils'
import { getCurrentInstance } from 'vue'
import LocalCache from '@/utils/cache'

const { proxy } = getCurrentInstance() // 获取当前组件实例上下文
// 路由对象
const route = useRoute()
const router = useRouter()
// el-col span栅格占据的列数
const wrapperSpan = 8
// 表格是否显示加载中
const isTableLoading = ref(false)
// 页面编码
const tableId = 'pageMaint'
// 保存成功按钮状态，默认不展示底部保存，取消按钮
const saveSuccessful = ref(false)
// 表格对象
const tableRef = ref(null)
const state = reactive({
  // 查询条件
  query: {
    taskArriveTime: '', // 任务到达时间
    processDefKey: '', // 流程名称
    beginTime: null, // 任务到达开始时间'
    endTime: null, // 任务到达结束时间
    taskDefKey: '', // 任务名称
    starter: '', // 流程发起人
    startDeptId: '', // 发起部门
    productName: '', // 产品名称
    prodPeriodNo: '', // 产品分期号
    consignee: '', // 委托人
    sequenceId: '', // 流程实例号
    instSubject: '', // 业务说明
    ifDeputedTask: '0', // 显示代理出去任务 1:显示，0:不显示
    claimCond: '', // 任务领取状态 0:全部 1未领取与已领取，2:已被领取
    taskStatus: 'open', // 任务状态 open:正运行  open_return：回退运行
    remark: '', // 备注
    approveDeadline: '', // 完成截止时间
    startApp: '', // 发起系统
    current: 1,
    size: 10,
  },
  // 表格数据
  dataList: [],
})
// 页面配置
const pageConfig: PageConfig = reactive({
  total: 0, // 总条数
  currentPage: 1, // 当前页码
})
// 表格列数据
const columns: Column[] = reactive([
  {
    label: '业务说明',
    prop: 'subject',
    align: 'center',
    width: '200',
  },
  {
    label: '流程名',
    prop: 'processName',
    align: 'center',
    width: '150',
  },
  {
    label: '节点名',
    prop: 'name',
    align: 'center',
    width: '150',
  },
  {
    label: '发起人',
    prop: 'starterName',
    align: 'center',
    width: '150',
  },
  {
    label: '发起部门',
    prop: 'startDeptName',
    align: 'center',
    width: '150',
  },
  {
    label: '到达时间',
    prop: 'startTime',
    align: 'center',
    width: '160',
    editType: 'date-picker',
  },
  {
    label: '完成截止日期',
    prop: 'approveDeadline',
    align: 'center',
    width: '160',
    editType: 'date-picker',
  },
  // {
  //   label: '任务链接',
  //   prop: 'manage',
  //   align: 'center',
  //   width: '250',
  // },
  {
    label: '任务状态',
    prop: 'taskStatusName',
    align: 'center',
    width: '120',
  },
  {
    label: '产品名称',
    prop: 'productName',
    align: 'center',
    width: '150',
  },
  {
    label: '分期名称',
    prop: 'prodPeriodName',
    align: 'center',
    width: '150',
  },
  {
    label: '项目名称',
    prop: 'projectName',
    align: 'center',
    width: '150',
  },
  {
    label: '合同号',
    prop: 'contractNo',
    align: 'center',
    width: '150',
  },
  {
    label: '领取状态',
    prop: 'claimStatus',
    align: 'center',
    width: '150',
    editType: 'select',
    editConfig: {
      options: [
        // 下拉框选项
        { value: 'false', label: '未领取' },
        { value: 'true', label: '已领取' },
        { value: 'claimed', label: '被领取' },
      ],
    },
  },
  {
    label: '流程状态',
    prop: 'processState',
    align: 'center',
    width: '150',
    editType: 'select',
    editConfig: {
      options: [
        // 下拉框选项
        { value: 'active', label: '正运行' },
        { value: 'suspend', label: '挂起' },
        { value: 'finish', label: '结束' },
        { value: 'manual-finish', label: '终止' },
      ],
    },
  },
  {
    label: '流程ID',
    prop: 'sequenceId',
    align: 'center',
    width: '180',
  },
  {
    label: '执行者',
    prop: 'completerName',
    align: 'center',
    width: '120',
  },
  {
    label: '任务类型',
    prop: 'taskClass',
    align: 'center',
    width: '150',
    editType: 'select',
    editConfig: {
      options: [
        // 下拉框选项
        { value: '0', label: '' },
        { value: '1', label: '委托给我的任务' },
        { value: '2', label: '代理出去的任务' },
        { value: '3', label: '代理出去的任务' },
        { value: '4', label: '代理给我的任务' },
      ],
    },
  },
  // {
  //   label: '委托代理履历',
  //   prop: 'his',
  //   align: 'center',
  //   width: '120',
  // },
  {
    label: '备注',
    prop: 'remark',
    align: 'center',
    minWidth: '100',
  },
  {
    label: '',
    prop: 'action',
    isCustomAction: true,
  },
])
// 选中列表集合
const checkedRows = ref([])
const reassignModelShow = ref(false) // 委托弹窗显示
// 选中列表集合值改变回调函数
const handleSelectionChange = (e) => {
  checkedRows.value = e
}
// 分页大小改变回调函数
const handleSizeChange = (e) => {
  pageConfig.pageSize = e
  pageConfig.currentPage = 1
  searchFn()
}
// 分页页码改变回调函数
const handleCurrentChange = (e) => {
  pageConfig.currentPage = e
  searchFn()
}
watch(
  () => state.query.taskArriveTime,
  (newVal) => {
    if (!newVal) {
      state.query.beginTime = ''
      state.query.endTime = ''
    } else {
      if (newVal.length == 2) {
        state.query.beginTime = newVal[0]
        state.query.endTime = newVal[1]
      } else {
        state.query.beginTime = ''
        state.query.endTime = ''
      }
    }
  }
)
// 搜索查询函数
const searchFn = (type?: string, columnsVal?: any) => {
  // 页面搜索数据组装
  const obj = initSearchData(type, columnsVal, columns, state.query)
  state.query = obj.queryData
  columns.values = obj.columns
  state.query.current = pageConfig.currentPage
  isTableLoading.value = true
  if (pageConfig.pageSize) state.query.size = pageConfig.pageSize
  const apiUrl = proxy.$Button_api('query', route.name)
  apiRequestPost(apiUrl, state.query)
    .then((res) => {
      isTableLoading.value = false
      if (res.data.success) {
        state.dataList = res.data.data.result
        Array.isArray(state.dataList) &&
          state.dataList.forEach((item: any) => {
            if (item.proxyState != '1' && item.proxyState != '4') {
              if (item.claimStatus == 'true' || item.claimStatus.replace(' ', '') == '') {
                item.dynamicActionConfig = [
                  { id: 'toTask', type: '办理' },
                  { id: 'reassign', type: '委托' },
                  { id: 'trace', type: '图形监控' },
                  { id: 'his', type: '查看委托代理履历' },
                ]
              } else if (item.claimStatus == 'false') {
                item.dynamicActionConfig = [
                  { id: 'claimTask', type: '领取' },
                  { id: 'trace', type: '图形监控' },
                  { id: 'his', type: '查看委托代理履历' },
                ]
              } else if (item.claimStatus == 'claimed') {
                item.dynamicActionConfig = [
                  { id: 'trace', type: '图形监控' },
                  { id: 'his', type: '查看委托代理履历' },
                ]
              }
            } else {
              item.dynamicActionConfig = [
                { id: 'trace', type: '图形监控' },
                { id: 'his', type: '查看委托代理履历' },
              ]
            }
          })
        console.log('state.dataList0001', state.dataList)
        pageConfig.pageSize = Number(res.data.data.size)
        pageConfig.total = Number(res.data.data.count)
      } else {
        // useMessage().error(res.data.message)
      }
    })
    .catch((error: any) => {
      isTableLoading.value = false
      // 处理错误
    })
}
// 批量操作
const bulkOperation = (type: string, singleId?: string) => {
  if (!checkedRows.value.length && !singleId) {
    useMessage().warning('请选择一条数据')
    return
  }
  let ids = []
  Array.isArray(checkedRows.value) &&
    checkedRows.value.forEach((item: any) => {
      if (item?.id) ids.push(item?.id)
    })
  let paramsObj = {}
  if (type === 'open') {
    // 批量打开
    if (Array.isArray(checkedRows.value)) {
      // const container = document.getElementById('linksContainer')
      for (let i = 0; i < checkedRows.value.length; i++) {
        if (checkedRows.value[i]?.claimStatus === 'true') {
          // const url = `${location.origin}${checkedRows.value[i].formUrl}`
          // console.log('批量打开---', url)
          // setTimeout(() => {
          //   window.open(url)
          //   console.log('批量打开---', url, i)
          // }, 1000 * i)
          setTimeout(() => {
            navigateToPage('toTask', checkedRows.value[i])
          }, 2000 * i)
          // const url = `${location.origin}${checkedRows.value[i].formUrl}`
          // const link = document.createElement('a')
          // link.href = url
          // link.textContent = `打开 ${url}`
          // link.target = '_blank'
          // link.style.display = 'block' // 或者其他CSS样式
          // container.appendChild(link)
        }
      }
    }
  } else if (type === 'claim') {
    // 批量领取 先判断一下是否有待领取任务，如果没有则直接提示；如果有则
    let tempIds = []
    if (singleId) {
      tempIds = [singleId]
    }
    Array.isArray(checkedRows.value) &&
      checkedRows.value.forEach((item: any) => {
        if (item?.claimStatus == 'false') tempIds.push(item?.id)
      })
    if (!tempIds.length) {
      useMessage().warning('所选记录不存在未领取任务')
    } else {
      const userData = LocalCache.getCache('user')
      const userId = userData.userId
      paramsObj = {
        taskList: tempIds, // 任务ID
        claimerId: userId, // 任务人ID
      }
      isTableLoading.value = true
      apiClaimTasksBulk(paramsObj)
        .then((res) => {
          isTableLoading.value = false
          searchFn()
        })
        .catch((error: any) => {
          isTableLoading.value = false
        })
    }
  } else if (type === 'delegate') {
    reassignForm.value.id = []
    let cannotReassign = false
    for (const item of checkedRows.value) {
      const { taskStatus, claimStatus, id } = item

      if (claimStatus === 'claimed') {
        useMessage().warning('选取的任务包含被领取任务，无法委托！')
        cannotReassign = true
        break // 一旦发现不能重分配的情况，立即退出循环
      }

      if (['completed', 'completed_return', 'closed'].includes(taskStatus)) {
        useMessage().warning(`选择的任务包含${taskStatus === 'closed' ? '已关闭' : '已完成'}任务，无法委托！`)
        cannotReassign = true
        break // 一旦发现不能重分配的情况，立即退出循环
      }

      reassignForm.value.id.push(id)
    }
    if (cannotReassign) return
    // 批量委托
    reassignForm.value.isBulk = true
    reassignModelShow.value = true
  }

  console.log('------2222', ids)
}
// 批量委托表单数据
const reassignForm = ref({
  loginName: '',
  userCName: '',
  isBulk: false, // 是否为批量委托
  id: [],
  confirmLoading: false,
})
const reassignConfirmSingle = (item) => {
  if (item.claimStatus != 'true' && item.taskStatus != 'open') {
    useMessage().warning('任务不在运行，无法委托')
    return
  }
  reassignForm.value.isBulk = false
  reassignModelShow.value = true
  reassignForm.value.id = [item.id]
}
// 单个委派、批量委托确认 如果传有id则为单个委托
const reassignConfirm = () => {
  if (!reassignForm.value.loginName) {
    useMessage().warning('请选择委托对象')
    return
  }
  let ids: string[] = []
  // let cannotReassign = false
  // if (reassignForm.value.isBulk) {
  // for (const item of checkedRows.value) {
  //   const { taskStatus, claimStatus, id } = item

  //   if (claimStatus === 'claimed') {
  //     useMessage().warning('选取的任务包含被领取任务，无法委托！')
  //     cannotReassign = true
  //     break // 一旦发现不能重分配的情况，立即退出循环
  //   }

  //   if (['completed', 'completed_return', 'closed'].includes(taskStatus)) {
  //     useMessage().warning(`选择的任务包含${taskStatus === 'closed' ? '已关闭' : '已完成'}任务，无法委托！`)
  //     cannotReassign = true
  //     break // 一旦发现不能重分配的情况，立即退出循环
  //   }

  //   ids.push(id)
  // }
  // } else {
  //   ids = reassignForm.value.id
  // }
  ids = reassignForm.value.id

  const tempUserCName = allStarterArr.value.find((item) => item.loginName === reassignForm.value.loginName)
  // reassignForm.value.userCName = tempUserCName.userCName
  const userData = LocalCache.getCache('user')
  let paramsObj = {
    operatorId: userData.loginName, //     委托操作用户ID operatorId
    operatorName: userData.userName, // 委托操作用户名称
    acceptorId: reassignForm.value.loginName, // 接收用户ID
    acceptorName: tempUserCName?.userCName, // 接收用户名称
    list: ids, // 委托任务ID列表 list
  }
  reassignForm.value.confirmLoading = true
  apiReassignTasksBulk(paramsObj)
    .then((res) => {
      reassignForm.value.confirmLoading = false
      if (res.data.success) {
        useMessage().success('委托成功')
        reassignModelShow.value = false
        if (reassignForm.value.isBulk) pageConfig.currentPage = 1
        searchFn()
      }
    })
    .catch(() => {
      reassignForm.value.confirmLoading = false
    })
}
function checkDateDisabled(date, targetTime) {
  if (targetTime) {
    return date > targetTime
  }
  return false
}

const disabledBeginDate = (date) => checkDateDisabled(date, state.query.endTime)
const disabledEndDate = (date) => checkDateDisabled(state.query.beginTime, date)

watch(
  () => reassignForm.value.userCName,
  (newVal) => {
    if (!newVal) {
      reassignForm.value.loginName = ''
    }
  }
)
const hisDialogVisible = ref(false)
const hisTaskId = ref('')
const { navigateToPage } = useRouteNavigation()
// 操作按钮回调
const handleActionClick = (item, rowData, btnInfo) => {
  if (item.id == 'toTask') {
    // openUrlFn('toTask', rowData)
    // router.push({
    //   name: 'EWTaskFormForwarder',
    //   query: {
    //     processInstanceId: rowData.processInstanceId,
    //     taskId: rowData.id,
    //   },
    // })
    navigateToPage(item.id, rowData)
  } else if (item.type == '委托') {
    reassignConfirmSingle(rowData)
  } else if (item.type == '领取') {
    bulkOperation('claim', rowData.id)
  } else if (item.id == 'trace') {
    // openUrlFn('trace', rowData)
    navigateToPage(item.id, rowData)
  } else if (item.id == 'his') {
    // openUrlFn('his', rowData)
    hisTaskId.value = rowData.id
    hisDialogVisible.value = true
  }
}
//导出
const exportLoading = ref(false)
const exportClick = () => {
  exportLoading.value = true
  apiMyFavorTaskExport(state.query)
    .then((res) => {
      exportLoading.value = false
      useMessage().success('导出成功')
    })
    .catch(() => {
      exportLoading.value = false
    })
}
// 所有流程
const allProcessesArr = ref([])
// 查询所有流程
const getAllProcesses = () => {
  apiQueryAllProcesses().then((res) => {
    if (res.data.success === true) {
      allProcessesArr.value = res.data.data || []
    }
  })
}

// 流程发起人
const allStarterArr = ref([])
// 查询所有流程发起人
const getAllProcessesStarter = () => {
  apiQueryUser().then((res) => {
    if (res.data.success === true) {
      allStarterArr.value = res.data.data || []
    }
  })
}

onMounted(() => {
  getAllProcesses()
  getAllProcessesStarter()
  // 获取查询条件缓存
  const { cachedQuery } = getQueryTableCache(route.path, tableId, state.query, columns.values)
  if (cachedQuery) state.query = cachedQuery
  searchFn()
})
</script>
<style lang="less" scoped>
::v-deep(.el-tabs__content) {
  min-height: calc(100vh - 180px);
}
.date-range-class {
  display: flex !important;
  ::v-deep(.el-form-item__content) {
    width: 220px !important;
    display: flex !important;
    justify-content: space-between !important;
    .el-input__prefix {
      display: none !important;
    }
    .el-input {
      width: 107px !important;
    }
  }
}
</style>
